﻿using Credera.Theta.API;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Credera.Theta.Modules.Environments.Commands
{
    [Command("LoadEnvironment")]
    [Synopsis("Loads the specified environment")]
    class LoadEnvironmentCommand : InputCommand
    {
        [Parameter(ordinalPosition: 1, autoCompleteValuesFunction: "GetEnvironmentNamesAutoComplete", useAutoCompleteForValidation: true)]
        [Synopsis("The name of the environment to list details for")]
        public string Environment { get; set; }

        public override void Invoke(CommandInvocationContext context)
        {
            EnvironmentLogic.Instance.Load(EnvironmentLogic.Instance.EnvironmentsCollection.Environments
                .FirstOrDefault(e => e.Name.Equals(this.Environment, StringComparison.OrdinalIgnoreCase)), base.Host.Modules, base.Out);
        }

        public void GetEnvironmentNamesAutoComplete(AutoCompleteValuesFunctionContext context)
        {
            context.Values.AddRange(EnvironmentLogic.Instance.EnvironmentsCollection.Environments.Select(e => e.Name));
        }

    }
}
